package com.fsnbigdata.repository;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import com.fsnbigdata.domain.EndangeredSpeciesImage;
import com.fsnbigdata.domain.EndangeredSpecies;
import com.fsnbigdata.domain.QEndangeredSpeciesImage;
import com.querydsl.core.types.Path;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * = EndangeredSpeciesImageRepositoryImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJpaRepositoryCustomImpl(repository = EndangeredSpeciesImageRepositoryCustom.class)
@Transactional(readOnly = true)
public class EndangeredSpeciesImageRepositoryImpl extends QueryDslRepositorySupportExt<EndangeredSpeciesImage> implements EndangeredSpeciesImageRepositoryCustom {

    /**
     * TODO Auto-generated constructor documentation
     */
    EndangeredSpeciesImageRepositoryImpl() {
        super(EndangeredSpeciesImage.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String LOCATION = "location";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CODE = "code";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CREATE_DATE = "createDate";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String DESCRIPTION = "description";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String ENDANGERED_SPECIES = "endangeredSpecies";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String AUTHOR = "author";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String URL = "url";

    /**
     * TODO Auto-generated method documentation
     *
     * @param endangeredSpecies
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<EndangeredSpeciesImage> findByEndangeredSpecies(EndangeredSpecies endangeredSpecies, GlobalSearch globalSearch, Pageable pageable) {
        QEndangeredSpeciesImage endangeredSpeciesImage = QEndangeredSpeciesImage.endangeredSpeciesImage;
        JPQLQuery<EndangeredSpeciesImage> query = from(endangeredSpeciesImage);
        Assert.notNull(endangeredSpecies, "endangeredSpecies is required");
        query.where(endangeredSpeciesImage.endangeredSpecies.eq(endangeredSpecies));
        Path<?>[] paths = new Path<?>[] { endangeredSpeciesImage.endangeredSpecies, endangeredSpeciesImage.code, endangeredSpeciesImage.description, endangeredSpeciesImage.location, endangeredSpeciesImage.author, endangeredSpeciesImage.url, endangeredSpeciesImage.createDate };
        applyGlobalSearch(globalSearch, query, paths);
        AttributeMappingBuilder mapping = buildMapper().map(ENDANGERED_SPECIES, endangeredSpeciesImage.endangeredSpecies).map(CODE, endangeredSpeciesImage.code).map(DESCRIPTION, endangeredSpeciesImage.description).map(LOCATION, endangeredSpeciesImage.location).map(AUTHOR, endangeredSpeciesImage.author).map(URL, endangeredSpeciesImage.url).map(CREATE_DATE, endangeredSpeciesImage.createDate);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, endangeredSpeciesImage);
    }
}
